export default {
	adviceResponse
}

// 统一处理
export function adviceResponse(config) {
	var myFirstPromise = new Promise(function(resolve, reject) {
		config.then(
			(res) => {
				if (res.data.code == 0) {
					//成功往下传
					resolve(res);
				} else if (res.data.code == 301) {
					//自定义一场
					uni.showToast({
						duration: 4000,
						icon: 'error',
						title: res.data.msg
					})
				} else {
					jumpIndex()
				}
			},
			(err) => {
				jumpIndex()
			}
		);
	});

	return myFirstPromise;
}

function jumpIndex() {
	uni.showToast({
		icon: 'none',
		title: '数据加载失败！'
	})

	//跳转到首页
	setTimeout(function() {
		uni.reLaunch({
			url: '/pages/index/index'
		})
	}, 3000)
}